﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ILX.Portal.DAL
{
    public class TaskActivityManager
    {
        string url;
        public TaskActivityManager(string siteUrl)
        {
            this.url = siteUrl;
        }
        private TaskActivityManager()
        {
        }
        
        public TaskActivityMasterDataContext context;
        TaskActivityMaster taskActivityMaster = new TaskActivityMaster();
        public void Create(TaskActivityMaster _taskActivityMaster)
        {
            
            context = new TaskActivityMasterDataContext(url);
            context.TaskActivityMaster.InsertOnSubmit(_taskActivityMaster);
            context.SubmitChanges();

        }

        public TaskActivityMaster Read(int id)
        {

            context = new TaskActivityMasterDataContext(url);
            var itemToUpdate = (from r in context.TaskActivityMaster where r.Id == id select r).First();
          

            return itemToUpdate;

        }

        public List<TaskActivityMaster> ReadAll()
        {
            context = new TaskActivityMasterDataContext(url);
            //var itemToUpdate1 = context.TaskActivityMaster.Where("a => a.Id == 2");
            var itemToUpdate = (from r in context.TaskActivityMaster where r.Id > 0 select r).ToList();
            return itemToUpdate;

        }

        public void Delete(int id)
        {

            context = new TaskActivityMasterDataContext(url);
            var itemToUpdate = (from r in context.TaskActivityMaster where r.Id == id select r).First();
            context.TaskActivityMaster.DeleteOnSubmit(itemToUpdate);
            context.SubmitChanges();

        }

        public void Update(TaskActivityMaster _taskActivityMaster)
        {

            context = new TaskActivityMasterDataContext(url);
            var itemToUpdate = (from r in context.TaskActivityMaster
                                where r.Id == _taskActivityMaster.Id
                                select r).First();
            itemToUpdate.Title = _taskActivityMaster.Title;
            itemToUpdate.AllowReSubmitInput = _taskActivityMaster.AllowReSubmitInput;
            itemToUpdate.ApprovalLevel = _taskActivityMaster.ApprovalLevel;
            itemToUpdate.ApprovalType = _taskActivityMaster.ApprovalType;
            itemToUpdate.ApproversId = _taskActivityMaster.ApproversId;
            itemToUpdate.DueDays = _taskActivityMaster.DueDays;
            itemToUpdate.FormType = _taskActivityMaster.FormType;
            itemToUpdate.OnReworkGoBackTo = _taskActivityMaster.OnReworkGoBackTo;
            itemToUpdate.TaskActivityId = _taskActivityMaster.TaskActivityId;
            context.SubmitChanges();
            

        }

    }
}
